package com.qs.education.controller;

import org.apache.log4j.Logger;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.qs.education.bean.api.ResponseListBean;
import com.qs.education.bean.beans.EducationSchoolBean;
import com.qs.education.bean.beans.EducationSchoolResponse;
import com.qs.education.bean.entity.EducationSchool;
import com.qs.education.service.ISchoolService;

/**
 * 
 * @class SubjectController
 * @author Jason
 * @description
 * @date Nov 7, 2018 3:34:05 PM
 */
@Controller
public class SchoolController {

	@Autowired
	private ISchoolService iSchoolService;
	
	private final Logger log = Logger.getLogger(this.getClass());
	
	/**
	 * @Description 查询所有学校
	 * @author Jason
	 * @date Nov 7, 2018
	 * @return
	 */
	@RequiresPermissions(value={"user:view"})
	@RequestMapping("/getSchool")
	public ModelAndView getSchool(){
		
		log.info("后台管理-->查询所有学校");
		ModelAndView mv=new ModelAndView("school/list");
		ResponseListBean<EducationSchoolBean> educationSchoolList =  iSchoolService.getSchoolList();
		mv.addObject("educationSchoolList", educationSchoolList);
		
		return mv;
	}
	
	/**
	 * @Description 根据条件查询学校
	 * @author Jason
	 * @date Nov 13, 2018
	 * @return
	 */
	@RequestMapping("/findSchoolByCondition")
	public ModelAndView findSchoolByCondition(EducationSchool school){
		
		log.info("后台管理-->根据条件查询学校");
		ModelAndView mv=new ModelAndView("school/list");
		ResponseListBean<EducationSchoolBean> educationSchoolList =  iSchoolService.findSchoolByCondition(school);
		mv.addObject("educationSchoolList", educationSchoolList);
		
		return mv;
	}
	
	/**
	 * @Description 编辑学校信息
	 * @author Jason
	 * @date Nov 14, 2018
	 * @param school
	 * @return
	 */
	@RequestMapping("/updateSchool")
	public ModelAndView updateSchool(EducationSchool school){
		
		log.info("后台管理-->编辑学校信息");
		ModelAndView mv=new ModelAndView("redirect:/getSchool");
		EducationSchoolResponse response =  iSchoolService.updateSchool(school);
		
		return mv;
	}
	
	/**
	 * @Description 删除学校信息
	 * @author Jason
	 * @date Nov 14, 2018
	 * @param school
	 * @return
	 */
	@RequestMapping("/deleteSchool")
	public ModelAndView deleteSchool(Integer schoolId){
		
		log.info("后台管理-->删除学校信息");
		ModelAndView mv=new ModelAndView("redirect:/getSchool");
		EducationSchoolResponse response =  iSchoolService.deleteSchool(schoolId);
		
		return mv;
	}
	
	/**
	 * @Description 添加学校
	 * @author Jason
	 * @date Nov 13, 2018
	 * @return
	 */
	@RequestMapping("/addSchool")
	public ModelAndView addSchool(EducationSchool school){
		
		log.info("后台管理-->添加学校");
		ModelAndView mv=new ModelAndView("redirect:/getSchool");
		EducationSchoolResponse response = iSchoolService.addSchool(school);

		return mv;
	}
	
	/**
	 * @Description 跳转添加学校页面
	 * @author Jason
	 * @date Nov 13, 2018
	 * @return
	 */
	@RequestMapping("/addSchoolHTML")
	public ModelAndView addSchoolHTML(){
		
		log.info("后台管理-->跳转添加学校页面");
		ModelAndView mv=new ModelAndView("school/add");

		return mv;
	}
	
	/**
	 * @Description 编辑学校信息页面跳转
	 * @author Jason
	 * @date Nov 14, 2018
	 * @return
	 */
	@RequestMapping("/updateSchoolHTML")
	public ModelAndView updateSchoolHTML(Integer schoolId){
		
		log.info("后台管理-->编辑学校信息页面跳转");
		ModelAndView mv=new ModelAndView("school/update");
		EducationSchoolResponse school = iSchoolService.findSchoolById(schoolId);
		mv.addObject("school", school);
		
		return mv;
	}
	
	/**
	 * @Description 学校详细信息页面跳转
	 * @author Jason
	 * @date Nov 14, 2018
	 * @return
	 */
	@RequestMapping("/schoolDetailHTML")
	public ModelAndView schoolDetailHTML(Integer schoolId){
		
		log.info("后台管理-->学校详细信息页面跳转");
		ModelAndView mv=new ModelAndView("school/detail");
		EducationSchoolResponse school = iSchoolService.findSchoolById(schoolId);
		mv.addObject("school", school);
		
		return mv;
	}
	
}
